<?php

function do_user_list() {

	
	include ('fen_fns.php');
	?>
	
	<script type="text/javascript">


var oTable;



$(document).ready(function() {

	
    $(".contentTopArea").hide();

    $('.buttonAdd').click(function(){
    	$(".contentTopArea").slideToggle(150);
    	$(".contentTopArea").load("users/add_user_form.php", function(){
        }); 
    });

	oTable = $('#example').dataTable({
        "sPaginationType": "full_numbers",
		"sDom": 'f<"toolbar">t<lip><"clear">'
	});

	
	$("div.toolbar").html('<input type=\"submit\" id=\"buttonModify\" value=\"Güncelle\" />  <input type=\"submit\" id=\"buttonPassword\" value=\"Şifre Sıfırla\" />');

	$(":input").bind("click keypress", function(evt) {
        var keyCode = evt.which || evt.keyCode;

			var sender = evt.target;
			if (sender.id == 'buttonModify') {

				$(".contentTopArea").hide();
				var sDataOne = oTable.$('input:checkbox:checked').val();
				var sData = oTable.$('input:checkbox:checked').serialize();
	
				if (sData.length == '0') {
					alert("Lütfen güncellemek istediğiniz kaydı seçiniz");
					return false;
				} else if (sData.length < 16) {

					$(".contentTopArea").load("users/add_user_form.php?userid="+sDataOne);
					$(".contentTopArea").slideToggle(150);
					return false;
									
				} else {
					alert("Aynı anda sadece tek bir kayıt güncellenebilir.");
					return false;	
				}
			} else if (sender.id == 'buttonPassword') {

				var sData = oTable.$('input:checkbox:checked').serialize();
				if (sData.length == '0') {
					alert("Lütfen şifresi sıfırlanacak kaydı seçiniz");
					return false;
				} else if (confirm('Seçmiş olduğunuz kullanıcının şifresi sıfırlanarak e-posta adresine yeni şifresi gönderilecektir. Onaylıyor musunuz?')){
				$.ajax({
					type:'POST',
					url:'users/password_reset.php',
					data:oTable.$('input:checkbox:checked').serialize(),
					success:function(cevap){
					    $("#sonuc").html(cevap);
						$('body').load('users.php');
					 	return false;
					}})

				return false;
				} else {
					return false;
				}
			}

        return true;
    });
} );

</script>
	
	<div class="contentTop">
		<div class="contentTopArea">
			<div id="formdiv"></div>
		</div>
	</div>
	<div class="contentMain">
		
		<br><br><button class="buttonAdd" id="buttonAdd" type="button">Kullanıcı Ekle</button><br><br><br>
		
	</div>
	<div class="showtable">

			<form id="form">
				<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
						<thead>
							<tr>
								<th id="left"></th>
								<th>Ünvan</th>
								<th>Adı</th>
								<th>Soyadı</th>							
								<th>Fakülte</th>
								<th>Bölüm</th>
								<th>Kullanıcı Adı / E-posta</th>
								<th>Yetki Seviyesi</th>
								<th>Son Giriş</th>
								<th>Durum</th>
							</tr>
						</thead>
						<tbody>
						
<?php 

						$query = $_DB->Query("SELECT
											fen_members.id as id,
											fen_members.titr as titr,
											fen_members.name as name,
											fen_members.surname as surname,
											fen_members.username as username,
											fen_faculty.faculty_name as faculty_name,
											fen_department.department_name as department_name,
											fen_members.email as email,
											fen_members.access_level as access_level,
											fen_members.status as status
											from fen_members, fen_faculty, fen_department
											WHERE
											fen_members.faculty_id = fen_faculty.id and fen_members.department_id = fen_department.id
											ORDER BY name ASC");
						$count = $_DB->GetResultNumber($query);
						

						
						

						for ($i=0; $i<$count; $i++)
						{
							
							if ($_DB->GetResultValue($query, $i, "status") == '1') {
								$status = "Aktif";
							} else {
								$status = "Pasif";
							}
							
							$id = $_DB->GetResultValue($query, $i, "id");
							
							$query2 = $_DB->Query("SELECT
									date_FORMAT(time , '%d-%m-%Y %H:%i') as logintime 
									FROM fen_logins
									WHERE
									fen_logins.user_id = '$id'
									ORDER BY time DESC");
							
							
							if ($_DB->GetResultValue($query, $i, "titr") == 'Prof. Dr.') {
								$titr = "<p id=\"hiddentitr\">1</p>Prof. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Doç. Dr.') {
								$titr = "<p id=\"hiddentitr\">2</p>Doç. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Yrd. Doç. Dr.') {
								$titr = "<p id=\"hiddentitr\">3</p>Yrd. Doç. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Öğr. Gör. Dr.') {
								$titr = "<p id=\"hiddentitr\">4</p>Öğr. Gör. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Öğr. Gör.') {
								$titr = "<p id=\"hiddentitr\">5</p>Öğr. Gör.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Uzm.') {
								$titr = "<p id=\"hiddentitr\">6</p>Uzm.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Okutman') {
								$titr = "<p id=\"hiddentitr\">7</p>Okutman";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Arş. Gör.') {
								$titr = "<p id=\"hiddentitr\">8</p>Arş. Gör.";
							}
							
							if ($_DB->GetResultValue($query, $i, "access_level") == '10') {
								$access_level = "Öğretim Üyesi";
							} else if ($_DB->GetResultValue($query, $i, "access_level") == '50') {
								$access_level = "Dekanlık";
							} else if ($_DB->GetResultValue($query, $i, "access_level") == '60') {
								$access_level = "Koordinatörlük";
							} else if ($_DB->GetResultValue($query, $i, "access_level") == '70') {
								$access_level = "Mali İşler";
							} else if ($_DB->GetResultValue($query, $i, "access_level") == '100') {
								$access_level = "Rektörlük";
							}
							
							echo "
								<tr>
									<td class=\"left\"><input id=\"showtableCheckBox\" type=\"checkbox\" name=\"check".$id."\" value=\"".$_DB->GetResultValue($query, $i, "id")."\"></td>
									<td>".$titr."</td>
									<td>".$_DB->GetResultValue($query, $i, "name")."</td>
									<td>".$_DB->GetResultValue($query, $i, "surname")."</td>
									<td>".$_DB->GetResultValue($query, $i, "faculty_name")."</td>
									<td>".$_DB->GetResultValue($query, $i, "department_name")."</td>
									<td>".$_DB->GetResultValue($query, $i, "username")."<br>".$_DB->GetResultValue($query, $i, "email")."</td>
									<td class=\"center\">".$access_level."</td>
									<td>".$_DB->GetResultValue($query2, "0", "logintime")."</td>
        							<td>".$status."</td>
								</tr>";		
						}
							


?>

						</tbody>
					</table>
					
				</form>

			</div>
	</div>




<?php
}